package other
{
	import data.PlotSurfaceData;
	
	import flash.geom.Point;

	public class Utils
	{
		public static function rand(a:Number, b:Number):Number {
			var r:Number = Math.random();
			return r * (b-a) + a;
		}
		
		public static function sq(a:Number):Number {
			return a*a;
		}
		
		public static function assert(a:Boolean):void {
			if (!a) {
				throw new Error();
			}
		}
		
		
		/**
		 * Translate from the pixel coordinate space to the cartesian space...
		 */ 
		public static function translatePx2Cart(p:Point):Point {
			var mp:Point = new Point(PlotSurfaceData.WIDTH_PX / 2.0, PlotSurfaceData.HEIGHT_PX / 2.0);
			
			return new Point(
				(p.x - mp.x) / PlotSurfaceData.PX_PER_UNIT,
				(p.y - mp.y) / PlotSurfaceData.PX_PER_UNIT
			);
		}
		/**
		 * ...and vice versa.
		 */
		public static function translateCart2Px(p:Point):Point {
			var mp:Point = new Point(PlotSurfaceData.WIDTH_PX / 2.0, PlotSurfaceData.HEIGHT_PX / 2.0);
			
			return new Point(
				p.x * PlotSurfaceData.PX_PER_UNIT + mp.x,
				p.y * PlotSurfaceData.PX_PER_UNIT + mp.y
			);
		}
		
	}
}